package org.huangrui.spark.scala.core.rdd.operate.transform

import org.apache.spark.{SparkConf, SparkContext}

/**
 * @Author hr
 * @Create 2024-10-17 17:50 
 */
object Spark11_Operate_Transform_KV_wordCount {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf().setMaster("local[*]").setAppName("spark")
    val sc = new SparkContext(conf)
    // TODO groupByKey方法作用是将KV类型的数据直接按照K对V进行分组
    //     (a, [1,3])
    //     (b, [2,4])
    val tuples = List(("a", 1), ("b", 2), ("a", 3), ("b", 4))
    sc.parallelize(tuples,2).groupByKey().mapValues(_.sum).collect().foreach(println)

    sc.stop()
  }
}
